

DEFINE VARIABLE part LIKE pt_part.
DEFINE VARIABLE d1 LIKE pt_desc1.
DEFINE VARIABLE d2 LIKE pt_desc2.

DEFINE VARIABLE d3 LIKE pt_desc1.
DEFINE VARIABLE d4 LIKE pt_desc2.

DEFINE VARIABLE d LIKE pt_desc1 FORMAT "x(90)".

DEFINE STREAM bf .

    INPUT FROM VALUE("c:\a.csv").   

    REPEAT ON ERROR UNDO, LEAVE WITH STREAM-IO WIDTH 132 :   

    IMPORT DELIMITER "," part d1 d2 .

    d1 = LEFT-TRIM(d1).
    d2 = RIGHT-TRIM(d2).

    d = d1 + d2 .

    IF LENGTH(d, "RAW") <= 40 THEN DO:
        d1 = d.
        d2 = "".
    END.
    ELSE DO:
        IF ASC(SUBSTRING(d, 40, 1, "RAW")) < 128 THEN DO:
            d1 = SUBSTRING(d, 1, 40, "RAW").
            d2 = SUBSTRING(d, 41, LENGTH(d) - 40, "RAW").
        END.
        ELSE DO:
            d1 = SUBSTRING(d, 1, 39, "RAW").
            d2 = SUBSTRING(d, 40, LENGTH(d, "RAW") - 39, "RAW").
        END.

        d3 = SUBSTRING(d, 1, R-INDEX(d1,","), "RAW") .
        d4 = SUBSTRING(d, R-INDEX(d1, ",") + 1, LENGTH(d, "RAW") - LENGTH(d3, "RAW"), "RAW").

        IF LENGTH(d3, "RAW") <= 40 AND LENGTH(d4, "RAW") <= 40 THEN DO:
            d1 = d3.
            d2 = d4.
        END.
    END.

    IF LENGTH(d1, "RAW") > 40 OR LENGTH(d2, "RAW") > 40 THEN
        MESSAGE part LENGTH(d1, "RAW") LENGTH(d2, "RAW") VIEW-AS ALERT-BOX.
/*
    DISPLAY d1 LENGTH(d1, "RAW") d2 LENGTH(d2, "RAW") WITH STREAM-IO WIDTH 120 .  
*/
    
    FIND FIRST pt_mstr EXCLUSIVE-LOCK WHERE pt_part = part NO-ERROR.
    IF AVAILABLE pt_mstr THEN DO:
        ASSIGN
            pt_desc1 = d1
            pt_desc2 = d2.
    END.
    

END.
